package com.just.bz_back.config;

import com.just.bz_back.constant.ConstantData;
import com.just.bz_back.dao.TypeMapper;
import com.just.bz_back.model.dto.JsonDataUtil;
import com.just.bz_back.service.RedisService;
import com.just.bz_back.model.Type;
import com.just.bz_back.model.TypeExample;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 初始化加载数据
 */
@Component
public class InitData implements ApplicationRunner {
    @Resource
    private TypeMapper typeMapper;
    @Resource
    private RedisService redisService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<Type> typeList=typeMapper.selectByExample(new TypeExample());
            String typeString =JsonDataUtil.obj2String(typeList);
            redisService.set(ConstantData.TYPE_LIST ,typeString);
    }
}
